package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.OrderdetailsBean;

import java.util.List;

/**
 * Created by mac on 2017/12/13.
 */

public class OrderdetailsAdapter extends RecyclerView.Adapter<OrderdetailsAdapter.MyViewHolder> {
    private Context context;
    private Button btevaluate;
    private OrderdetailsBean.DataBean goods;
    private List<OrderdetailsBean.DataBean.OrderItemBean> orderdata;
    private MyViewHolder myViewHolder;

    public OrderdetailsAdapter(Context context, OrderdetailsBean.DataBean goods, List<OrderdetailsBean.DataBean.OrderItemBean> orderdata) {
        this.context = context;
        this.goods = goods;
        this.orderdata = orderdata;
    }

    @Override
    public OrderdetailsAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.orderdetails_item,null);
        myViewHolder=new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(OrderdetailsAdapter.MyViewHolder holder, int position) {

//    Glide.with(context).load(goods.get(position).getGoodsImg()).into(myViewHolder.im_shop);
//    myViewHolder.shop_name.setText(goods.get(position).getGoodsName());
//    myViewHolder.shop_color.setText(goods.get(position).getGoodsColor());
//    myViewHolder.shop_size.setText(goods.get(position).getGoodsSize());
        OrderdetailsBean.DataBean.OrderItemBean orderItemBean = orderdata.get(position);
        Glide.with(context).load(orderItemBean.getGoodsImg()).into(myViewHolder.im_shop);
        myViewHolder.shop_name.setText(orderItemBean.getGoodsName());
        OrderdetailsBean.DataBean.OrderItemBean.ParamBean param = orderItemBean.getParam();
        String color = param.get颜色() == null ? "无" : param.get颜色();   //三元运算符   判断param.getColor()是否为null  如果是null则取 : 前面的值，否则后面的值
        String brand = param.get尺寸() == null ? "**" : param.get尺寸();   //同上
        myViewHolder.shop_color.setText(color + "；");   //商品的颜色
        myViewHolder.shop_size.setText(brand);

    }

    @Override
    public int getItemCount() {
        return orderdata.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView im_shop;
        TextView shop_name;
        TextView shop_color;
        TextView shop_size;
        TextView shop_xj;
        TextView shop_yj;
        TextView shop_num;
        public   Button bt_money;
        public  Button bt_comm;
        TextView shop_ddbm;
        public MyViewHolder(View itemView) {
            super(itemView);

            bt_money = (Button) itemView.findViewById(R.id.orderdetails_tmoney);
            im_shop = (ImageView) itemView.findViewById(R.id.orderdetails_shopim);
            shop_name = (TextView) itemView.findViewById(R.id.orderdetails_shopname);
            shop_color = (TextView) itemView.findViewById(R.id.orderdetails_shopcolor);
            shop_size = (TextView) itemView.findViewById(R.id.orderdetails_shopsize);
            bt_comm = (Button) itemView.findViewById(R.id.orderdetails_comm);
            shop_xj = (TextView) itemView.findViewById(R.id.orderdetails_xj);
            shop_yj = (TextView) itemView.findViewById(R.id.orderdetails_yj);
            shop_num = (TextView) itemView.findViewById(R.id.orderdetails_num);
            shop_ddbm = (TextView) itemView.findViewById(R.id.orderdetails_shopid);

        }

        public void setData(Context context, OrderdetailsBean.DataBean.OrderItemBean orderItemBean) {
            Glide.with(context).load(orderItemBean.getGoodsImg()).into(im_shop);
            shop_name.setText(orderItemBean.getGoodsName());
            OrderdetailsBean.DataBean.OrderItemBean.ParamBean param = orderItemBean.getParam();
            String color = param.get颜色() == null ? "无" : param.get颜色();   //三元运算符   判断param.getColor()是否为null  如果是null则取 : 前面的值，否则后面的值
            String brand = param.get尺寸() == null ? "**" : param.get尺寸();   //同上
            shop_color.setText(color + "；");   //商品的颜色
            shop_size.setText(brand);
            shop_xj.setText("¥"+orderItemBean.getPrice()+"");
            shop_yj.setText("¥"+orderItemBean.getOrginPrice()+"");
            shop_num.setText("x"+orderItemBean.getCount()+"");
            shop_ddbm.setText("订单编码:"+orderItemBean.getGoodsId());
        }
    }
}
